<?php
	header("Content-type: text/html; charset=utf-8");
	Verifiy_purview(0);
	$link = mysql_connect($dbhost, $dbroot, $dbpass);
	$dblist = mysql_list_dbs();
	$i = 0;
    while ($i < mysql_num_rows($dblist)) 
	{
        $db[] = mysql_db_name($dblist,$i);$i++;        
    }unset($i);

	if(in_array($dbname,$db))
	{
		$tables = array('articles','source','users','message','comment','insertData','products');
		mysql_select_db($dbname,$link);
		mysql_query("DROP TABLE IF EXISTS ".implode(',',$tables));
		foreach($tables as $val)
		{
			switch($val)
			{
				case 'articles':
					$sql = "CREATE TABLE `articles` (
							  `id` int(8) NOT NULL auto_increment,
							  `title` varchar(100) NOT NULL,
							  `tage` varchar(20) default NULL,
							  `catename` varchar(50) default NULL,
							  `cates` varchar(10) default NULL,
							  `description` varchar(255) default NULL,
							  `faceimg` varchar(255) default NULL,
							  `type` int(2) NOT NULL default '1',
							  `updatetime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
							  `content` mediumtext,
							  `addtime` int(10) NOT NULL,
							  `author` varchar(100) NOT NULL default '37.5',
							  `author_id` int(8) default '0',
							  PRIMARY KEY  (`id`)
							) ENGINE=MyISAM AUTO_INCREMENT=34 DEFAULT CHARSET=utf8";
					break;
				case 'source':
				   $sql = 	'CREATE TABLE `source` (
							  `id` int(8) NOT NULL auto_increment,
							  `name` varchar(50) NOT NULL,
							  `link` varchar(100) NOT NULL,
							  `img` varchar(100) default NULL,
							  `content` mediumtext,
							  `cates` int(2) default NULL,
							  `addtime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
							  `step` int(2) default NULL,
							  PRIMARY KEY  (`id`),
							  UNIQUE KEY `link` (`link`)
							) ENGINE=MyISAM DEFAULT CHARSET=utf8';
					break;
				case 'users':
					$sql = "CREATE TABLE `users` (
							  `id` int(10) NOT NULL auto_increment,
							  `face` varchar(150) default NULL,
							  `nickname` varchar(50) NOT NULL,
							  `email` varchar(100) NOT NULL,
							  `phone` varchar(15) NOT NULL,
							  `password` varchar(32) NOT NULL,
							  `level` int(1) default '0',
							  `logintime` timestamp NULL default NULL on update CURRENT_TIMESTAMP,
							  `addtime` int(10) default NULL,
							  `status` enum('0','1','2') default '1',
							  PRIMARY KEY  (`id`),
							  UNIQUE KEY `email` (`email`)
							) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8";
					break;
				case 'message':
					$sql = 'CREATE TABLE `message` (
							  `id` int(8) NOT NULL auto_increment,
							  `name` varchar(50) default NULL,
							  `email` varchar(100) default NULL,
							  `web` varchar(100) default NULL,
							  `message` mediumtext,
							  `ip` varchar(15) default NULL,
							  `addtime` timestamp NOT NULL default CURRENT_TIMESTAMP,
							  `step` int(2) default "0",
							  PRIMARY KEY  (`id`),
							  UNIQUE KEY `id` USING BTREE (`id`)
							) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8';
					break;
				case 'comment':
					$sql = "CREATE TABLE `comment` (
							  `id` int(10) NOT NULL auto_increment,
							  `tid` int(10) default '0',
							  `cid` int(10) default '0',
							  `face` varchar(100) default NULL,
							  `uid` int(10) default NULL,
							  `ip` varchar(16) NOT NULL,
							  `uname` varchar(50) default NULL,
							  `address` varchar(50) NOT NULL,
							  `content` varchar(255) NOT NULL,
							  `status` enum('2','1') default '1',
							  `addtime` timestamp NULL default CURRENT_TIMESTAMP,
							  PRIMARY KEY  (`id`)
							) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8";
					break;
				case 'products':
					$sql = "CREATE TABLE `products` (
  `id` int(8) NOT NULL auto_increment,
  `title` varchar(100) NOT NULL,
  `tage` varchar(20) default NULL,
  `catename` varchar(50) default NULL,
  `cates` varchar(10) default NULL,
  `description` varchar(255) default NULL,
  `faceimg` varchar(255) default NULL,
  `status` int(2) NOT NULL default '1',
  `updatetime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `content` mediumtext,
  `addtime` int(10) NOT NULL,
  `author` varchar(100) NOT NULL default '37.5',
  `author_id` int(8) default '0',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=50 DEFAULT CHARSET=utf8";
					break;
				case 'insertData':
					$_->users->_insert(array('nickname'=>'admin','email'=>'2004yzw@163.com','phone'=>'13006616675','password'=>md5(888),'level'=>0,'addtime'=>time()))?die('注册成功！'):die('erro:insertData:insert data to users fail!');
					break;
			}
			mysql_query($sql,$link)?"":die('erro:table:'.$val.' create fail!');			
		}die('OK');
	}else{
		mysql_query('CREATE DATABASE '.$dbname)?die('erro:db create success,submit it again create table.'):die('erro:db create fail!');
	}
?>